﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Intorise.Common;
using System.Net;

namespace Model
{
    public class Command
    {
        public string Name { get; set; }
        public byte[] Data { get; set; }
    }

    public interface IAttactDataPack
    {
        byte[] GetData(Map map, Player player, Monster monster);

        byte[] GetData(Map map, Player player, List<Monster> monsters);
    }

    /// <summary>
    /// 黑龙波
    /// </summary>
    public class HLB : Skill
    {
        static byte[] tag = new byte[] { 0x00, 0x07, 0xA9, 0xBB, 0xC0, 0x9C, 0x01, 0x0E };

        public HLB()
        {
            ID = 0x00C09C01;
            Name = "黑龙波";
            CD = 0.3;
            MP = 102;
            AttackRange = 13;
            IsFixedCD = false;
            TargetCount = 6;
        }

        public override byte[] GetData(Map map, Player player, Monster monster)
        {
            return GetData(map, player, new List<Monster> { monster });
        }


        public override byte[] GetData(Map map, Player player, List<Monster> monsters)
        {
            var data = Tools.Contact(tag, map.Data,
                             new byte[] { (byte)(player.CurrentLine * 2) }, DataPackager.GetPointData(player.X, player.Y), DataPackager.GetNetworkData((short)monsters.Count));
            monsters.ForEach(w =>
            {
                data = Tools.Contact(data, DataPackager.GetNetworkData(w.InstanceID), player.Version);
            });
            data = Tools.Contact(data, DataPackager.GetNetworkData((short)monsters.Count));
            monsters.ForEach(w =>
            {
                data = Tools.Contact(data, new byte[] { 0x02 });
            });
            data = Tools.Contact(DataPackager.GetNetworkData(data.Length), data);
            return data;
        }
    }

    /// <summary>
    /// 陨石术
    /// </summary>
    public class YSS : Skill
    {
        public YSS()
        {
            ID = 0x00B89C01;
            Name = "陨石术";
            CD = 0.3;
            MP = 1;
            AttackRange = 13;
            IsFixedCD = false;
            TargetCount = 1;
        }

        public override byte[] GetData(Map map, Player player, Monster monster)
        {
            return Tools.Contact(new byte[] { 0x00, 0x00, 0x00, 0x11, 0x00, 0x01, 0x8F, 0x39, 0xb8, 0x9c, 0x01, 0x08 }, DataPackager.GetNetworkData(monster.InstanceID), player.Version);
            //return Tools.Contact(new byte[] { 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 0x8F, 0x39, 0x00, 0x00, 0x27, 0x1C, 0x00, 0x00, 0x00, 0x07 }, DataPackager.GetNetworkData(monster.InstanceID));
        }


        public override byte[] GetData(Map map, Player player, List<Monster> monsters)
        {
            throw new NotImplementedException();
        }
    }

    /// <summary>
    /// 霹雳回旋斩
    /// </summary>
    public class PLHXZ : Skill
    {
        public PLHXZ()
        {
            ID = 0x00018F3900002717;
            Name = "霹雳回旋斩攻击者";
        }

        public override byte[] GetData(Map map, Player player, Monster monster)
        {
            return Tools.Contact(new byte[] { 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 0x8f, 0x39, 0x00, 0x00, 0x27, 0x17, 0x00, 0x00, 0x00, 0x01 }, DataPackager.GetNetworkData(monster.InstanceID));
        }


        public override byte[] GetData(Map map, Player player, List<Monster> monsters)
        {
            var data = new byte[] { 0x00, 0x01, 0x8f, 0x39, 0x00, 0x00, 0x27, 0x17 };
            //data = Tools.Contact(data, DataPackager.GetNetworkData(monsters.Count), DataPackager.GetNetworkData(monsters.First().InstanceID));
            data = Tools.Contact(data, DataPackager.GetNetworkData(6), DataPackager.GetNetworkData(monsters.First().InstanceID));
            data = Tools.Contact(DataPackager.GetNetworkData(data.Length), data);
            return data;
        }
    }

    /// <summary>
    /// 霹雳地裂斩
    /// </summary>
    public class PLDLZ : Skill
    {
        public PLDLZ()
        {
            ID = 0x00018F3900002719;
            Name = "霹雳地裂斩攻击者";
        }

        public override byte[] GetData(Map map, Player player, Monster monster)
        {
            return Tools.Contact(new byte[] { 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 0x8f, 0x39, 0x00, 0x00, 0x27, 0x19, 0x00, 0x00, 0x00, 0x00 }, DataPackager.GetNetworkData(monster.InstanceID));
        }


        public override byte[] GetData(Map map, Player player, List<Monster> monsters)
        {

            var data = new byte[] { 0x00, 0x01, 0x8f, 0x39, 0x00, 0x00, 0x27, 0x19 };
            data = Tools.Contact(data, DataPackager.GetNetworkData(monsters.Count), DataPackager.GetNetworkData(monsters.First().InstanceID));
            data = Tools.Contact(DataPackager.GetNetworkData(data.Length), data);
            return data;
        }
    }

    /// <summary>
    /// 地狱火
    /// </summary>
    public class DYH : Skill
    {
        public DYH()
        {
            ID = 0x00018F3900002722;
            Name = "地狱火攻击者";
        }

        public override byte[] GetData(Map map, Player player, Monster monster)
        {
            return Tools.Contact(new byte[] { 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 0x8f, 0x39, 0x00, 0x00, 0x27, 0x22, 0x00, 0x00, 0x00, 0x01 }, DataPackager.GetNetworkData(monster.InstanceID));
        }


        public override byte[] GetData(Map map, Player player, List<Monster> monsters)
        {
            var data = new byte[] { 0x00, 0x01, 0x8f, 0x39, 0x00, 0x00, 0x27, 0x22 };
            data = Tools.Contact(data, DataPackager.GetNetworkData(monsters.Count), DataPackager.GetNetworkData(monsters.First().InstanceID));
            data = Tools.Contact(DataPackager.GetNetworkData(data.Length), data);
            return data;
        }
    }


    public class CTJ : Skill
    {
        public CTJ()
        {
            ID = 0xCC9C01;
            Name = "穿透箭";
        }

        public override byte[] GetData(Map map, Player player, Monster monster)
        {
            var dir = DataPackager.GetFangXiang(player.Location, monster.Location);
            //var dir = new byte[] { 0x04 };
            //return Tools.Contact(new byte[] { 0x00, 0x00, 0x00, 0x11, 0x00, 0x01, 0x8f, 0x3A, 0xCC, 0x9C, 0x01 }, dir, DataPackager.GetNetworkData(monster.InstanceID), player.Version); //穿透箭
            return Tools.Contact(new byte[] { 0x00, 0x00, 0x00, 0x11, 0x00, 0x01, 0x8f, 0x39, 0xCC, 0x9C, 0x01 }, dir, DataPackager.GetNetworkData(monster.InstanceID), player.Version); //穿透箭
        }


        public override byte[] GetData(Map map, Player player, List<Monster> monsters)
        {
            return GetData(map, player, monsters.First());
        }
    }

    public class DCJ : Skill
    {
        public DCJ()
        {
            ID = 0xCA9C01;
            Name = "多重箭";
        }

        public override byte[] GetData(Map map, Player player, Monster monster)
        {
            var dir = DataPackager.GetFangXiang(player.Location, monster.Location);
            return Tools.Contact(new byte[] { 0x00, 0x00, 0x00, 0x11, 0x00, 0x01, 0x8f, 0x39, 0xCA, 0x9C, 0x01 }, dir, DataPackager.GetNetworkData(monster.InstanceID), player.Version);
        }


        public override byte[] GetData(Map map, Player player, List<Monster> monsters)
        {
            return GetData(map, player, monsters.First());
        }
    }

    public class JY : Skill
    {
        public JY()
        {
            ID = 0xDA9C01;
            Name = "箭雨";
            CD = 5;
            MP = 50;
            AttackRange = 13;
            IsFixedCD = true;
            TargetCount = 6;
        }

        public override byte[] GetData(Map map, Player player, Monster monster)
        {
            var dir = DataPackager.GetFangXiang(player.Location, monster.Location);
            return Tools.Contact(new byte[] { 0x00, 0x00, 0x00, 0x11, 0x00, 0x01, 0x8f, 0x39, 0xDA, 0x9C, 0x01 }, dir, DataPackager.GetNetworkData(monster.InstanceID), player.Version);
        }


        public override byte[] GetData(Map map, Player player, List<Monster> monsters)
        {
            return GetData(map, player, monsters.First());
        }
    }

    public class LJF : Skill
    {
        static byte[] tag = new byte[] { 0x00, 0x00, 0x00, 0x11, 0x00, 0x01, 0x8f, 0x39, 0xBA, 0x9C, 0x01 };
        public LJF()
        {
            ID = 0xBA9C01;
            Name = "龙卷风";
            CD = 0.5;
            MP = 34;
            AttackRange = 13;
            IsFixedCD = true;
            TargetCount = 4;
        }

        public override byte[] GetData(Map map, Player player, Monster monster)
        {
            var dir = DataPackager.GetFangXiang(player.Location, monster.Location);
            return Tools.Contact(tag, dir, DataPackager.GetNetworkData(monster.InstanceID), player.Version);
        }


        public override byte[] GetData(Map map, Player player, List<Monster> monsters)
        {
            return GetData(map, player, monsters.First());
        }
    }
}
